package com.qf.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.qf.dao.MemberDao;
import com.qf.pojo.Member;
import com.qf.service.MemberService;
import com.qf.utils.MD5Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhouhao
 * @create 2021-12-25 11:46
 */
@Service(interfaceClass = MemberService.class)
@Transactional
public class MemberServiceImpl implements MemberService {

    @Autowired
    MemberDao memberDao;
    //根据电话号码查询member
    @Override
    public Member findMemberByTelephone(String telephone) {
        return memberDao.findmemberByTelephone(telephone);
    }

    //添加会员
    @Override
    public void add(Member member) {
        if(member.getPassword()!=null){
            member.setPassword(MD5Utils.md5(member.getPassword()));
        }
        memberDao.addMember(member);
    }

    //获取会员统计
    @Override
    public List<Integer> findMemberCountByMonth(List<String> list) {
        List<Integer> memberCount = new ArrayList<>();
        for (String month:list){
            month = month + "-31";//将光有年月的字符串日期转换成符合查询数据库的年月日的类型(如3月的总数是3.1-3.31的所有)
            Integer count =  memberDao.findMemberCountByMonth(month);
            memberCount.add(count);
        }
        return memberCount;
    }
}
